<template>
    <div id="parts">
        <div class="operation"><el-button v-if="menuId==='4725'" @click="insertList" class="slot-btn-top" type="primary" size="small">发放任务</el-button>
          <el-input placeholder="请输如订单号" v-model="search.ordernums" class="input-with-select" style="width:300px">
            <el-button slot="append" icon="el-icon-search" @click="searchSubmit"></el-button>
        </el-input>
        </div>
        <el-table :data="dataList" :highlight-current-row="true" stripe border class="table-index" :height="tableHeight" style="width: 100%;" :header-cell-style="getRowClass" :row-class-name="tableRowClassName">
            <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
            <el-table-column prop="ordernums" label="订单号" sortable min-width="140"></el-table-column>
            <el-table-column prop="makeNo" label="令号" sortable min-width="140"></el-table-column>
            <el-table-column prop="needDate" label="订单下达时间" sortable min-width="140"></el-table-column>
            <el-table-column prop="khxxName" label="客户信息" sortable min-width="270"></el-table-column>
            <el-table-column prop="goodsname" label="商品名称" sortable min-width="140"></el-table-column>
            <el-table-column prop="rwzt" label="任务是否启动"  sortable width="60">
                <template  slot-scope="scope">
                    <span :class="scope.row.rwzt===1?'el-icon-circle-check cl-success':''"></span>
                </template>
            </el-table-column>
            <el-table-column prop="isproviderstockup" label="供应商是否开始备货"  sortable width="60">
                <template  slot-scope="scope">
                    <span :class="scope.row.isproviderstockup===1?'el-icon-circle-check cl-success':''"></span>
                </template>
            </el-table-column>
            <el-table-column prop="ischeckupgoods" label="备货过程是否检查" sortable width="60">
                <template  slot-scope="scope">
                    <span :class="scope.row.ischeckupgoods===1?'el-icon-circle-check cl-success':''"></span>
                </template>
            </el-table-column>
            <el-table-column prop="isproviderdeliver" label="供应商是否发货"  sortable width="60">
                <template  slot-scope="scope">
                    <span :class="scope.row.isproviderdeliver===1?'el-icon-circle-check cl-success':''"></span>
                </template>
            </el-table-column>
            <el-table-column prop="hwzt" label="货物是否已到"  sortable width="60">
                 <template  slot-scope="scope">
                    <span :class="scope.row.hwzt===1?'el-icon-circle-check cl-success':''"></span>
                </template>
            </el-table-column>
            <el-table-column prop="hkzt" label="货款是否已结" sortable width="60">
                 <template  slot-scope="scope">
                    <span :class="scope.row.hkzt===1?'el-icon-circle-check cl-success':''"></span>
                </template>
            </el-table-column>
            <el-table-column prop="invoicenums" label="发票号" sortable min-width="130"></el-table-column>
            <el-table-column prop="invoicesum" label="发票金额" sortable min-width="120"></el-table-column>

            <el-table-column prop="sum" label="应付款" sortable min-width="110"></el-table-column>

            <el-table-column fixed="right" label="操作" sortable align="center" width="90">
                <template slot-scope="scope"><el-button @click="updateList(scope.row)" type="text" size="small">编辑</el-button></template>
            </el-table-column>
        </el-table>
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                       :current-page="pagination.currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagination.pageSize"
                       layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"></el-pagination>

        <!-- 详情信息 -->
        <el-dialog :title="dialogTitle" width="90%" top="30px" :visible.sync="isDialog" :close-on-click-modal="false">
            <el-tabs v-model="activeName" @tab-click="handleClick" style="padding-bottom: 15px;">
                <el-tab-pane label="任务信息" name="1" class="dialog1" :style="dialogHeightPane">

                    <!---->
                    <h3 class="dialog-plate-title"><span>基本信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right" label-width="180px">
                        <el-form-item label="订单号"><el-input v-model="dialogList.ordernums" :disabled="!dialogListDisabled.ordernums"></el-input></el-form-item>
                        <el-form-item label="商品名称"><el-input v-model="dialogList.goodsname" :disabled="!dialogListDisabled.goodsname"></el-input></el-form-item>
                        <el-form-item label="客户信息"><el-select v-model="dialogList.khxx" :disabled="!dialogListDisabled.khxx"><el-option v-for="item in customers" :key="item.id" :value="item.id" :label="item.name"></el-option></el-select></el-form-item>
                        <el-form-item label="任务发布人"><el-input v-model="dialogList.bzryname" :disabled="!dialogListDisabled.bzryname"></el-input></el-form-item>
                        <el-form-item label="任务发布时间"><el-input v-model="dialogList.fbsj" :disabled="!dialogListDisabled.fbsj" ></el-input></el-form-item>
                        <el-form-item label="采购人员"><el-select v-model="dialogList.fzry" :disabled="!dialogListDisabled.fzry"><el-option v-for="item in purchases" :key="item.user_id" :value="item.user_id" :label="item.name"></el-option></el-select></el-form-item>
                        <el-form-item label="付款方式"><el-input v-model="dialogList.paymentMethod" :disabled="!dialogListDisabled.fbsj" ></el-input></el-form-item>
                        <el-form-item label="付款方式"><el-input v-model="dialogList.makeNo" :disabled="!dialogListDisabled.fbsj" ></el-input></el-form-item>
                    </el-form>

                    <!---->
                    <h3 class="dialog-plate-title"><span>启动信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right" label-width="180px">
                        <el-form-item label="任务是否启动"><el-select v-model="dialogList.rwzt" :disabled="!dialogListDisabled.rwzt" @change="change2Time('rwzt','tssj')"><el-option :value="1" label="是"></el-option><el-option :value="0" label="否"></el-option></el-select></el-form-item>
                        <el-form-item label="任务启动时间"><el-input v-model="dialogList.tssj" :disabled="!dialogListDisabled.tssj"></el-input></el-form-item>
                    </el-form>

                    <!---->
                    <h3 class="dialog-plate-title"><span>发货信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right" label-width="180px">
                        <el-form-item label="供应商是否开始备货"><el-select v-model="dialogList.isproviderstockup" :disabled="!dialogListDisabled.isproviderstockup" @change="change2Time('isproviderstockup','startstockuptime')"><el-option :value="1" label="是"></el-option><el-option :value="2" label="否"></el-option></el-select></el-form-item>
                        <el-form-item label="开始备货创建时间"><el-input v-model="dialogList.startstockuptime" :disabled="!dialogListDisabled.startstockuptime"></el-input></el-form-item>
                        <el-form-item label="供应商备货过程是否检查"><el-select v-model="dialogList.ischeckupgoods" :disabled="!dialogListDisabled.ischeckupgoods"  @change="change2Time('ischeckupgoods','checkuptime')"><el-option :value="1" label="是"></el-option><el-option :value="2" label="否"></el-option></el-select></el-form-item>
                        <el-form-item label="过程检查创建时间"><el-input v-model="dialogList.checkuptime" :disabled="!dialogListDisabled.checkuptime"></el-input></el-form-item>
                        <el-form-item label="供应商是否发货"><el-select v-model="dialogList.isproviderdeliver" :disabled="!dialogListDisabled.isproviderdeliver" @change="change2Time('isproviderdeliver','providerdelivertime')"><el-option :value="1" label="是"></el-option><el-option :value="2" label="否"></el-option></el-select></el-form-item>
                        <el-form-item label="发货创建时间"><el-input v-model="dialogList.providerdelivertime" :disabled="!dialogListDisabled.providerdelivertime"></el-input></el-form-item>
                    </el-form>

                    <!---->
                    <h3 class="dialog-plate-title"><span>收货信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right" label-width="180px">
                        <el-form-item label="货物是否已到"><el-select v-model="dialogList.hwzt" :disabled="!dialogListDisabled.hwzt" @change="change2Time('hwzt','sfhsj')"><el-option :value="0" label="【空】"></el-option><el-option :value="1" label="是"></el-option><el-option :value="2" label="否"></el-option></el-select></el-form-item>
                        <el-form-item label="收货日期"><el-date-picker v-model="dialogList.sfhrq" :disabled="!dialogListDisabled.sfhrq" type="date" placeholder="选择日期" style="width: 200px;"></el-date-picker></el-form-item>
                        <el-form-item label="收货填写时间"><el-input v-model="dialogList.sfhsj" :disabled="!dialogListDisabled.sfhsj"></el-input></el-form-item>
                        <el-form-item label="库房人员"><el-select v-model="dialogList.kfry" :disabled="!dialogListDisabled.kfry"><el-option v-for="item in rooms" :key="item.user_id" :value="item.user_id" :label="item.name"></el-option></el-select></el-form-item>
                    </el-form>

                    <!---->
                    <h3 class="dialog-plate-title"><span>财务信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right" label-width="180px">
                        <el-form-item label="货款是否已结"><el-select v-model="dialogList.hkzt" :disabled="!dialogListDisabled.hkzt"  @change="change2Time('hkzt','sfksj')"><el-option :value="0" label="【空】"></el-option><el-option :value="1" label="是"></el-option><el-option :value="2" label="否"></el-option></el-select></el-form-item>
                        <el-form-item label="付款金额"><el-input v-model="dialogList.sum" :disabled="!dialogListDisabled.sum"></el-input></el-form-item>
                        <el-form-item label="付款日期"><el-date-picker v-model="dialogList.sfkrq" :disabled="!dialogListDisabled.sfkrq" type="date" placeholder="选择日期" style="width: 200px;"></el-date-picker></el-form-item>
                        <el-form-item label="付款填写时间"><el-input v-model="dialogList.sfksj" :disabled="!dialogListDisabled.sfksj"></el-input></el-form-item>
                        <el-form-item label="发票是否已到"><el-select v-model="dialogList.fpzt" :disabled="!dialogListDisabled.fpzt" @change="change2Time('fpzt','ksfpsj')"><el-option :value="0" label="【空】"></el-option><el-option :value="1" label="是"></el-option><el-option :value="2" label="否"></el-option></el-select></el-form-item>
                        <el-form-item label="发票号"><el-input v-model="dialogList.invoicenums" :disabled="!dialogListDisabled.invoicenums"></el-input></el-form-item>
                        <el-form-item label="发票金额"><el-input v-model="dialogList.invoicesum" :disabled="!dialogListDisabled.invoicesum"></el-input></el-form-item>
                        <el-form-item label="收发票日期"><el-date-picker v-model="dialogList.ksfprq" :disabled="!dialogListDisabled.ksfprq" type="date" placeholder="选择日期" style="width: 200px;"></el-date-picker></el-form-item>
                        <el-form-item label="收发票填写时间"><el-input v-model="dialogList.ksfpsj" :disabled="!dialogListDisabled.ksfpsj"></el-input></el-form-item>
                        <el-form-item label="财务人员"><el-select v-model="dialogList.cwry" :disabled="!dialogListDisabled.cwry"><el-option v-for="item in finance" :key="item.user_id" :value="item.user_id" :label="item.name"></el-option></el-select></el-form-item>
                        <el-form-item label="任务完成时间"><el-input v-model="dialogList.wcsj" :disabled="!dialogListDisabled.wcsj"></el-input></el-form-item>
                    </el-form>

                    <div style="text-align: right">
                        <el-button @click="submitList" type="primary">确 定</el-button>
                    </div>
                </el-tab-pane>
                <el-tab-pane v-if="dialogType !== '1'" label="过程状态信息" name="2" :style="dialogHeightPane">
                    <el-button @click="insertProcessStateList" type="primary" size="small">新增</el-button>
                    <el-table :data="processStateData.slice((pagination1.currentPage-1)*pagination1.pageSize,pagination1.currentPage*pagination1.pageSize)" stripe border class="table-index" :height="dialogTableHeight" style="width: 100%;" :header-cell-style="getRowClass">
                        <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
                        <el-table-column prop="spname" label="商品名称" sortable min-width="140"></el-table-column>
                        <el-table-column prop="commodityuse" label="商品用途" :formatter="formatDityUse" sortable min-width="100"></el-table-column>
                        <el-table-column prop="spxh" label="商品型号" sortable min-width="120"></el-table-column>
                        <el-table-column prop="spjhsl" label="商品计划数量" sortable min-width="130"></el-table-column>
                        <el-table-column prop="spjhdj" label="商品计划单价" sortable min-width="130"></el-table-column>
                        <el-table-column prop="spjhzj" label="商品计划总价" sortable min-width="130"></el-table-column>
                        <el-table-column prop="planarrivedtime" label="计划到货时间" :formatter="formatTimestampToDate" sortable min-width="130"></el-table-column>
                        <el-table-column prop="spjhsfsj" label="计划付款时间" :formatter="formatTimestampToDate" sortable min-width="130"></el-table-column>
                        <el-table-column prop="spsjsl" label="商品实际数量" sortable min-width="130"></el-table-column>
                        <el-table-column prop="spsjdj" label="商品实际单价" sortable min-width="130"></el-table-column>
                        <el-table-column prop="spsjzj" label="商品实际总价" sortable min-width="130"></el-table-column>
                        <el-table-column fixed="right" label="操作" sortable align="center" width="75">
                            <template slot-scope="scope">
                                <el-button @click="updateProcessStateList(scope.row)" type="text" size="small">编辑
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination background @size-change="handleSizeChange1" @current-change="handleCurrentChange1" :current-page="pagination1.currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagination1.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="processStateData.length"></el-pagination>
                </el-tab-pane>
                <el-tab-pane v-if="dialogType !== '1'" label="备注记录信息" name="3" :style="dialogHeightPane">
                    <el-button @click="insertNotesRecordList" type="primary" size="small" >新增</el-button>
                    <el-table :data="notesRecordData.slice((pagination2.currentPage-1)*pagination2.pageSize,pagination2.currentPage*pagination2.pageSize)" stripe border class="table-index" :height="dialogTableHeight" style="width: 99%;" :header-cell-style="getRowClass">
                        <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
                        <el-table-column prop="txrname" label="填写人" sortable min-width="100"></el-table-column>
                        <el-table-column prop="tdsj" label="填写时间" :formatter="formatTimestampToTime" sortable min-width="160"></el-table-column>
                        <el-table-column prop="tdnr" label="填写内容" sortable min-width="500"></el-table-column>
                        <el-table-column fixed="right" label="操作" sortable align="center" width="75">
                            <template slot-scope="scope">
                                <el-button @click="updateNotesRecordList(scope.row)" type="text" size="small">编辑</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination background @size-change="handleSizeChange2" @current-change="handleCurrentChange2" :current-page="pagination2.currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagination2.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="notesRecordData.length"></el-pagination>
                </el-tab-pane>
            </el-tabs>
        </el-dialog>

        <!-- 过程状态信息 -->
        <el-dialog :title="dialogProcessStateTitle" width="900px" center :visible.sync="isProcessStateDialog" :close-on-click-modal="false" style="padding-bottom: 15px;">
            <el-form :inline="true" class="demo-form-inline" v-model="dialogProcessStateList" label-position="right" label-width="180px">
                <el-form-item label="商品用途"><el-select v-model="dialogProcessStateList.commodityuse" @change="getProcessStateSelectUserData"><el-option value="" label="【空】"></el-option><el-option :value="0" label="耗材生产"></el-option><el-option :value="1" label="机器生产"></el-option><el-option :value="2" label="其他"></el-option></el-select></el-form-item>
                <el-form-item label="商品名称"><el-select v-model="dialogProcessStateList.spmc"><el-option v-for=" item in processStateSelectUserData" :key="item.tid" :value="item.tid" :label="item.name"></el-option></el-select></el-form-item>
                <el-form-item label="商品型号"><el-input v-model="dialogProcessStateList.spxh"></el-input></el-form-item>
                <el-form-item label="商品计划数量"><el-input v-model="dialogProcessStateList.spjhsl"></el-input></el-form-item>
                <el-form-item label="商品计划单价"><el-input v-model="dialogProcessStateList.spjhdj"></el-input></el-form-item>
                <el-form-item label="商品计划总价"><el-input v-model="dialogProcessStateList.spjhzj"></el-input></el-form-item>
                <el-form-item label="计划到货时间"><el-date-picker v-model="dialogProcessStateList.planarrivedtime" type="date" placeholder="选择日期" style="width: 200px;"></el-date-picker></el-form-item>
                <el-form-item label="计划付款时间"><el-date-picker v-model="dialogProcessStateList.spjhsfsj" type="date" placeholder="选择日期" style="width: 200px;"></el-date-picker></el-form-item>
                <el-form-item label="商品实际数量"><el-input v-model="dialogProcessStateList.spsjsl" :disabled="dialogProcessStateTitle ==='添加'"></el-input></el-form-item>
                <el-form-item label="商品实际单价"><el-input v-model="dialogProcessStateList.spsjdj" :disabled="dialogProcessStateTitle ==='添加'"></el-input></el-form-item>
                <el-form-item label="商品实际总价"><el-input v-model="dialogProcessStateList.spsjzj" :disabled="dialogProcessStateTitle ==='添加'"></el-input></el-form-item>
                <el-form-item label="商品添加时间"><el-input v-model="dialogProcessStateList.sptjsj" disabled></el-input></el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: right;">
                <el-button @click="submitProcessStateList" type="primary">确 定</el-button>
            </div>
        </el-dialog>

        <!-- 备注记录信息 -->
        <el-dialog :title="dialogNotesRecordTitle" width="500px" center :visible.sync="isNotesRecordDialog" :close-on-click-modal="false" style="padding-bottom: 15px;">
            <el-form :inline="true" class="demo-form-inline" v-model="dialogNotesRecordList" label-position="right" label-width="180px">
                <el-form-item label="填写人"><el-input v-model="dialogNotesRecordList.txr" disabled></el-input></el-form-item>
                <el-form-item label="填写时间"><el-input v-model="dialogNotesRecordList.tdsj" disabled></el-input></el-form-item>
                <el-form-item label="填写内容"><el-input type="textarea" :rows="8" v-model="dialogNotesRecordList.tdnr"></el-input></el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: right;"><el-button @click="submitNotesRecordList" type="primary">确 定</el-button>
            </div>
        </el-dialog>


    </div>
</template>

<script>
import cgbHttp from '@/axios/cgbHttp.js'
    export default {
        name: "",
        data() {
            let token = sessionStorage.getItem("tokenId");
            let menuId = sessionStorage.getItem('menuId');
            let tableHeight = (menuId === '4725') ? (document.documentElement.clientHeight - 170) : (document.documentElement.clientHeight - 140);
            let roleList = JSON.parse(localStorage.getItem('roles'));
            let role = {
                    ROLE_operation_cg_cg:false,
                    ROLE_operation_cg_kf:false,
                    ROLE_operation_cg_cw:false
                }
            roleList.forEach(item=>{
                if(item.role_code==='ROLE_operation_cg_cg'){
                    role.ROLE_operation_cg_cg=true;
                }
                if(item.role_code==='ROLE_operation_cg_kf'){
                    role.ROLE_operation_cg_kf= true;
                }
                if(item.role_code==='ROLE_operation_cg_cw'){
                    role.ROLE_operation_cg_cw=true;
                }
            })
            return {
                role,
                tokenId: token,
                menuId: menuId,
                keyWord:'',
                activeName: '1',
                customers: [],
                purchases: [],
                rooms: [],
                finance: [],
                tableHeight: tableHeight,
                dataList: [],
                allDataList:[],
                //基本信息
                isDialog: false,
                dialogTitle: '',
                dialogType: '',
                dialogHeightPane: {
                    height: (document.documentElement.clientHeight - 180) + 'px',
                    overflowY: 'auto'
                },
                dialogTableHeight: document.documentElement.clientHeight - 280,
                dialogList: {
                    bzry: '',
                    bzryname: '',
                    checkuptime: '',
                    cwry: '',
                    days: '',
                    fbsj: '',
                    fpzt: '',
                    fzry: '',
                    goodsname: '',
                    hkzt: '',
                    hwzt: '',
                    invoicenums: '',
                    invoicesum: '',
                    ischeckupgoods: '',
                    isproviderdeliver: '',
                    isproviderstockup: '',
                    kfry: '',
                    khxx: '',
                    khxxName: '',
                    ksfprq: '',
                    ksfpsj: '',
                    ordernums: '',
                    plandelivertime: '',
                    planpaytime: '',
                    productbatch: '',
                    productbatchs: '',
                    providerdelivertime: '',
                    rwlx: '',
                    rwwczt: '',
                    rwzt: '',
                    sfhrq: '',
                    sfhsj: '',
                    sfkrq: '',
                    sfksj: '',
                    startstockuptime: '',
                    sum: '',
                    tcode: '',
                    tid: '',
                    tssj: '',
                    wcsj: '',
                    xsry: '',
                },
                dialogListDisabled: {
                    bzry: true,
                    bzryname: true,
                    checkuptime: true,
                    cwry: true,
                    days: true,
                    fbsj: true,
                    fpzt: true,
                    fzry: true,
                    goodsname: true,
                    hkzt: true,
                    hwzt: true,
                    invoicenums: true,
                    invoicesum: true,
                    ischeckupgoods: true,
                    isproviderdeliver: true,
                    isproviderstockup: true,
                    kfry: true,
                    khxx: true,
                    khxxName: true,
                    ksfprq: true,
                    ksfpsj: true,
                    ordernums: true,
                    plandelivertime: true,
                    planpaytime: true,
                    productbatch: true,
                    productbatchs: true,
                    providerdelivertime: true,
                    rwlx: true,
                    rwwczt: true,
                    rwzt: true,
                    sfhrq: true,
                    sfhsj: true,
                    sfkrq: true,
                    sfksj: true,
                    startstockuptime: true,
                    sum: true,
                    tcode: true,
                    tid: true,
                    tssj: true,
                    wcsj: true,
                    xsry: true,
                },


                //过程状态信息
                isProcessStateDialog: false,
                dialogProcessStateTitle: '',
                dialogProcessStateList: {
                    commodityuse: '',
                    planarrivedtime: '',
                    rwlx: '',
                    sjtotal: '',
                    sjwhereweek: '',
                    spid: '',
                    spjhdj: '',
                    spjhsfsj: '',
                    spjhsl: '',
                    spjhzj: '',
                    spmc: '',
                    spname: '',
                    spsjdj: '',
                    spsjsl: '',
                    spsjzj: '',
                    sptjsj: '',
                    spxh: '',
                    tid: '',
                    total: '',
                    whereWeek: '',
                },
                processStateData: [],
                processStateSelectUserData: [],

                //备注记录
                isNotesRecordDialog: false,
                dialogNotesRecordTitle: '',
                dialogNotesRecordList: {
                    tdid:'',
                    txr:'',
                    tdsj:'',
                    tdnr:'',
                    tid:'',
                },
                notesRecordData: [],
                /**搜索 */
                search:{
                    ordernums:'',/**商品名称 */
                    NAME:'',/**客户名称 */
                    ORDERNUMS:'',/**订单号搜索 */
                },
                /** 采购任务列表分页*/
                pagination:{
                    currentPage: 1,
                    pageSize: 10,
                    total:0
                },
                /** 过程状态信息分页*/
                pagination1:{
                    currentPage:1,
                    pageSize:10,
                },
                /**备注记录信息 */
                pagination2:{
                    currentPage:1,
                    pageSize:10,
                },

            };
        },
        created() {
            this.getData();
            this.getCustomer();
            this.getPurchase();
            this.getRoom();
            this.getFinance();
        },
        methods: {
            getCustomer() {
                let self = this;
                cgbHttp.allSupplierListHc().then(res=>{
                    self.customers=res.content;
                })
                // cgbHttp.customersList({type:2}).then(res=>{
                //     self.customers=res.content;
                // })
            },
            getPurchase() {/** 获取采购人员列表*/
                let self = this;
                cgbHttp.purchasesPersonList({roleid:128}).then(res=>{
                     self.purchases = res.content;
                })
            },
            getRoom() {/** 获取库房人员列表*/
                let self = this;
                cgbHttp.purchasesPersonList({roleid:129}).then(res=>{
                     self.rooms = res.content;
                })
            },
            getFinance() {/** 获取财务人员列表*/
               let self = this;
                cgbHttp.purchasesPersonList({roleid:130}).then(res=>{
                     self.finance = res.content;
                })
            },
             getData(){

                 let  self = this;
                let data ={
                    currentPage:self.pagination.currentPage,
                    pageSize:self.pagination.pageSize,
                    ordernums:self.search.ordernums
                    // key:sekf.search.key,
                    // GOODSNAME:self.search.GOODSNAME,
                    // NAME:self.search.NAME,
                    // ORDERNUMS:self.search.ORDERNUMS
                }
                switch(self.menuId){
                    case '4725'://待办
                        data.rwlx=1;
                        data.rwwczt=0
                        break;
                    case '5170'://待收货
                        data.rwlx=1;
                        data.rwzt=1;
                        data.rwwczt=0;
                        data.hwzt=0;
                        break;
                    case '5171'://代付款
                        data.rwlx=1;
                        data.rwzt=1;
                        data.rwwczt=0;
                        data.hkzt=0;
                        break;
                    case '4729'://已办
                        data.rwlx=1;
                        data.rwwczt=1;
                        break;
                }
                cgbHttp.CgxsTaskinfo(data).then(res=>{
                    res.content.records.forEach((element,i)=> {
                        let currentData =new Date().getTime();
                        element.timeWaring= element.needDate!==null&&(new Date(element.needDate).getTime()-currentData<86400000)?'warning-row':'';
                    });
                    self.dataList = res.content.records;
                    self.pagination.total = res.content.total;

                });
            },
            tableRowClassName(data){
                return data.row.timeWaring
            },
            insertList() {
                this.isDialog = true;
                this.dialogType = '1';
                this.dialogListDisabled = {
                    ordernums: true,
                    goodsname: true,
                    khxx:true,
                    khxxName:true,
                    bzry: false,
                    bzryname: false,
                    fbsj: false,
                    fzry: true,
                    rwzt: false,
                    tssj: false,
                    isproviderstockup: false,
                    ischeckupgoods: false,
                    checkuptime: false,
                    isproviderdeliver: false,
                    providerdelivertime: false,
                    hwzt: false,
                    sfhrq: false,
                    sfhsj: false,
                    kfry: false,
                    hkzt: false,
                    sfkrq: false,
                    sfksj: false,
                    fpzt: false,
                    invoicenums: false,
                    invoicesum: false,
                    ksfprq: false,
                    ksfpsj: false,
                    cwry: false,
                    wcsj: false,
                    days: false,
                    plandelivertime: false,
                    planpaytime: false,
                    productbatch: false,
                    productbatchs: false,
                    rwlx: false,
                    rwwczt: false,
                    startstockuptime: false,
                    sum: false,
                    tcode: false,
                    tid: false,
                    xsry: false,
                };
                this.dialogList = {
                    ordernums:'',
                    goodsname: '',
                    khxx: '',
                    khxxName: '',
                    bzry: '',
                    bzryname: '',
                    fbsj: this.this2Time(),
                    fzry:'',
                    rwzt: '',
                    tssj: '',
                    isproviderstockup: '',
                    ischeckupgoods: '',
                    checkuptime: '',
                    isproviderdeliver: '',
                    providerdelivertime: '',
                    hwzt: '',
                    sfhrq: '',
                    sfhsj: '',
                    kfry: '',
                    hkzt: '',
                    sfkrq: '',
                    sfksj: '',
                    fpzt: '',
                    invoicenums: '',
                    invoicesum: '',
                    ksfprq: '',
                    ksfpsj: '',
                    cwry: '',
                    wcsj: '',
                    days: '',

                    plandelivertime: '',
                    planpaytime: '',
                    productbatch: '',
                    productbatchs: '',
                    rwlx: '1',
                    rwwczt: '',
                    startstockuptime: '',
                    sum: '',
                    tcode: '',
                    tid: '',
                    xsry: '',
                };
            },
            updateList(row) {
                this.isDialog = true;
                this.dialogType = '2';
                this.activeName = '1';
                this.dialogListDisabled = {
                    ordernums: this.menuId === '4725' ? true : false,
                    khxx:this.menuId === '4725' ? true : false,
                    khxxName:this.menuId === '4725' ? true : false,
                    bzry: false,
                    bzryname: false,
                    fbsj: false,
                    fzry: this.menuId === '4725' ? true : false,
                    rwzt: this.menuId === '4725' ? true : false,
                    tssj: false,
                    isproviderstockup: this.role.ROLE_operation_cg_cg,
                    ischeckupgoods: this.role.ROLE_operation_cg_cg,
                    checkuptime: false,
                    isproviderdeliver: this.role.ROLE_operation_cg_cg,
                    providerdelivertime: false,
                    hwzt: this.role.ROLE_operation_cg_kf,
                    sfhrq: this.role.ROLE_operation_cg_kf,
                    sfhsj: false,
                    kfry:this.role.ROLE_operation_cg_kf,
                    hkzt: this.role.ROLE_operation_cg_cw,
                    sfkrq:  this.role.ROLE_operation_cg_cw,
                    sfksj: false,
                    fpzt: this.role.ROLE_operation_cg_cw,
                    invoicenums: this.role.ROLE_operation_cg_cw,
                    invoicesum: this.role.ROLE_operation_cg_cw,
                    ksfprq: this.role.ROLE_operation_cg_cw,
                    ksfpsj: false,
                    cwry: this.role.ROLE_operation_cg_cw,
                    wcsj: false,
                    days: false,
                    goodsname: false,
                    plandelivertime: false,
                    planpaytime: false,
                    productbatch: false,
                    productbatchs: false,
                    rwlx: false,
                    rwwczt: false,
                    startstockuptime: false,
                    sum: this.role.ROLE_operation_cg_cw,
                    tcode: false,
                    tid: false,
                    xsry: false,
                };
                this.dialogList = row;
                this.dialogList.khxx = Number(this.dialogList.khxx);
            },
            submitList() {
                let _this = this;
                let url;
                if (_this.dialogType === '1') {
                    url = '/api/adscm/operation/cgxsTaskinfo/insert?tokenId=' + _this.tokenId;
                } else if (_this.dialogType === '2') {
                    url = '/api/adscm/operation/cgxsTaskinfo/update?tokenId=' + _this.tokenId;
                }

                _this.dialogList.sfhrq = _this.timestampToTime( _this.dialogList.sfhrq  );
                _this.dialogList.sfkrq   = _this.timestampToTime( _this.dialogList.sfkrq  );
                _this.dialogList.ksfprq   = _this.timestampToTime( _this.dialogList.ksfprq  );

                let param = new URLSearchParams();
                param.append('data', JSON.stringify(_this.dialogList));
                this.$http({
                    url: url,
                    method: 'post',
                    headers: {'deviceCode': 'A95ZEF1-47B5-AC90BF3'},
                    data: param,
                }).then(function (res) {
                    console.log( res.data )

                    if (res.data.statusCode == 200) {
                        _this.isDialog = false;
                        _this.getData();
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },


            //过程状态信息
            getProcessStateSelectUserData() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/cgxsCommodityinfo/queryBySpmc?type='+_this.dialogProcessStateList.commodityuse+'&tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {

                    console.log( res.data )

                    if (res.data.statusCode == 200) {
                        _this.processStateSelectUserData = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            getProcessStateData() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/cgxsCommodityinfo/queryByTid?tid=' + _this.dialogList.tid + '&tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    console.log(res.data )

                    if (res.data.statusCode == 200) {
                        _this.processStateData = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            insertProcessStateList() {
                this.isProcessStateDialog = true;
                this.dialogProcessStateTitle = '添加';
                this.dialogProcessStateList = {
                    commodityuse: '',
                    planarrivedtime: '',
                    rwlx: '',
                    sjtotal: '',
                    sjwhereweek: '',
                    spid: '',
                    spjhdj: '',
                    spjhsfsj: '',
                    spjhsl: '',
                    spjhzj: '',
                    spmc: '',
                    spname: '',
                    spsjdj: '',
                    spsjsl: '',
                    spsjzj: '',
                    sptjsj: this.this2Time(),
                    spxh: '',
                    tid: this.dialogList.tid,
                    total: '',
                    whereWeek: '',
                };
            },
            updateProcessStateList(row) {
                this.isProcessStateDialog = true;
                this.dialogProcessStateTitle = '编辑';
                this.dialogProcessStateList = row;
                this.dialogProcessStateList.commodityuse = parseInt(this.dialogProcessStateList.commodityuse);
                this.getProcessStateSelectUserData();
            },
            submitProcessStateList() {
                let _this = this;
                let url;
                if (_this.dialogProcessStateTitle === '添加') {
                    url = '/api/adscm/operation/cgxsCommodityinfo/insert?tokenId=' + _this.tokenId;
                } else if (_this.dialogProcessStateTitle === '编辑') {
                    url = '/api/adscm/operation/cgxsCommodityinfo/update?tokenId=' + _this.tokenId;
                }
                this.dialogProcessStateList.planarrivedtime = this.timestampToTime(this.dialogProcessStateList.planarrivedtime);
                this.dialogProcessStateList.spjhsfsj = this.timestampToTime(this.dialogProcessStateList.spjhsfsj);

                let param = new URLSearchParams();
                param.append('data', JSON.stringify(_this.dialogProcessStateList));
                this.$http({
                    url: url,
                    method: 'post',
                    headers: {'deviceCode': 'A95ZEF1-47B5-AC90BF3'},
                    data: param,
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.isProcessStateDialog = false;
                        _this.getProcessStateData();

                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },

            //备注记录信息
            getNotesRecordData() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/baseTaskdetailinfo/queryByTid?tid=' +_this.dialogList.tid+ '&tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {

                    console.log( res.data )

                    if (res.data.statusCode == 200) {
                        _this.notesRecordData = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            insertNotesRecordList() {
                this.isNotesRecordDialog = true;
                this.dialogNotesRecordTitle = '添加';
                this.dialogNotesRecordList = {
                    tdid:'',
                    txr:'',
                    tdsj:'',
                    tdnr:'',
                    tid:this.dialogList.tid,
                };
            },
            updateNotesRecordList(row) {

                console.log( row )

                this.isNotesRecordDialog = true;
                this.dialogNotesRecordTitle = '编辑';
                this.dialogNotesRecordList = row;
            },
            submitNotesRecordList() {
                let _this = this;
                let url;
                if (_this.dialogNotesRecordTitle === '添加') {
                    url = '/api/adscm/operation/baseTaskdetailinfo/insert?tokenId=' + _this.tokenId;
                } else if (_this.dialogNotesRecordTitle === '编辑') {
                    url = '/api/adscm/operation/baseTaskdetailinfo/update?tokenId=' + _this.tokenId;
                }
                let param = new URLSearchParams();
                param.append('data', JSON.stringify(_this.dialogNotesRecordList));

                this.$http({
                    url: url,
                    method: 'post',
                    headers: {'deviceCode': 'A95ZEF1-47B5-AC90BF3'},
                    data: param,
                }).then(function (res) {

                    console.log( res.data )

                    if (res.data.statusCode == 200) {
                        _this.isNotesRecordDialog = false;
                        _this.getNotesRecordData();
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },


            change2Time( isOk ,eTime){
                if ( this.dialogList[isOk] == 1) {
                    let date = new Date();
                    let Y = date.getFullYear() + '-';
                    let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                    let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + " ";
                    let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ":";
                    let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ":";
                    let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
                    this.dialogList[eTime] =  Y + M + D + h + m + s;
                }
            },
            handleClick(tab, event) {
                if (tab.name === '2') {
                    this.getProcessStateData();
                } else if (tab.name === '3') {
                    this.getNotesRecordData();
                }
            },
            handleSizeChange: function (size) {
                this.pagination.currentPage=1;
                this.pagination.pageSize = size;
                this.getData();
            },
            searchData(){
                this.pagination.currentPage=1;
                this.getData();
            },
            handleCurrentChange: function (currentPage) {
                this.pagination.currentPage=currentPage;
                this.getData();
            },
            handleSizeChange1: function (size) {
                this.pagination1.currentPage=1;
                this.pagination1.pageSize = size;
            },
            handleCurrentChange1: function (currentPage) {
                this.pagination1.currentPage=currentPage;
            },
            handleSizeChange2: function (size) {
                this.pagination2.currentPage=1;
                this.pagination2.pageSize = size;
            },
            handleCurrentChange2: function (currentPage) {
                this.pagination2.currentPage=currentPage;
            },
            formatTimestampToTime:function(row, column, cellValue, index) {
        return cellValue ? this.timestampToTime(cellValue) : '';
    },
            formatDityUse:function(row, column, cellValue, index) {
                return cellValue == '0' ? '耗材生产' : (cellValue == '1' ? '机器生产' : (cellValue == '2' ? '其他' : ''));
            },
            formatTimestampToDate:function(row, column, cellValue, index) {
                return cellValue ? this.timestampToTime(cellValue).substr(0,10) : '';
            },
            timestampToTime(timestamp) {
                if (timestamp) {
                    let date = new Date(timestamp);
                    let Y = date.getFullYear() + '-';
                    let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                    let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + " ";
                    let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ":";
                    let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ":";
                    let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
                    return timestamp ? Y + M + D + h + m + s : '';
                } else {
                    return '';
                }
            },
            this2Time() {
                    let date = new Date();
                    let Y = date.getFullYear() + '-';
                    let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                    let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + " ";
                    let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ":";
                    let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ":";
                    let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
                    return  Y + M + D + h + m + s ;
            },
            searchSubmit(){
                let self = this;
                self.pagination.currentPage=1;
                self.getData();
            }
        }
    }
</script>

<style scoped>

    #parts .el-table--small {
        font-size: 13px;
    }

    #parts .el-table .cell,
    #parts .el-table th div {
        padding-left: 0;
        padding-right: 0;
    }

    #parts .el-tab-pane.dialog1 .el-form {
        margin-bottom: 30px;
    }
    .cl-success{
    line-height: 100%;
    font-size:18px;
}

</style>
